﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class update_score_detail : System.Web.UI.Page
{
    string score;
    string Sno;
    string Cno;
    string Sname;
    string Cname;

    protected void Page_Load(object sender, EventArgs e)
    {
        Sname = Request.QueryString["Sname"];
        Cname = Request.QueryString["Cname"];
        Response.Write("<h1>请输入学生'" + Sname + "'的课程'" + Cname + "'的新成绩：</h1>");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        score = TextBox1.Text.Trim();
        Sno = Request.QueryString["Sno"];
        Cno = Request.QueryString["Cno"];

        string conn = "Data Source= . ;Initial Catalog=XSXK; User ID=sa; pwd=123";
        SqlConnection connection = new SqlConnection(conn);

        try
        {
            if (string.IsNullOrEmpty(score))
            {
                Response.Write("<h1>更新失败，成绩信息不能为空！！</h1>");
            }
            else
            {

                connection.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection = connection;

                string str_sql = " update result set score='"+score+"' where Sno='"+Sno+"' and Cno='"+Cno+"' ) ";
                comm.CommandText = str_sql;
                //comm.ExecuteScalar();  //如果为查询语句，则用ExecuteScalar()；否则，用ExecuteNonQuery()
                comm.ExecuteNonQuery();


                Response.Write("<h1>成功更新成绩！</h1>");
            }
        }

        catch (SqlException ex)
        {
            Response.Write(ex.Message);
        }

        connection.Close();//关闭数据库连接
    }
}